import React, { Component } from 'react';
import { WhiteSpace } from 'antd-mobile';
import WithdrawalLogItem from '../WithdrawalLogItem/WithdrawalLogItem';
import YwxListView from '../../common/YwxListView/YwxListView';

import './WithdrawalLogList.less';


export default class StatusList extends Component {


    constructor(props) {
        super(props);
        this.state = {
            pageSize: 15,
            list: [],
            nomore: false,
            visible: false,
            count: 0
        }
    }


    componentDidMount() {
        this.page = 1;
        this.fetchData();
    };


    fetchData = (callback) => {
        this.isLoading = true
        React.$utils.request({
            url: '/app/withdrawList',
            params: {
                status: this.props.type || 0,
                pageNo: this.page,
                pageSize: this.state.pageSize
            }
        }).then(res => {
            this.isLoading = false
            this.setState({
                count: res.count,
                noMore: res.length === 0,
                list: (this.page === 1 ? [] : this.state.list).concat(res)
            });
            callback && callback(res);
        }).catch(err => {
            this.isLoading = false
        })
    }

    onRefresh = () => {
        this.page = 1;
        this.fetchData();
    };

    onEndReached = (type) => {
        if (this.isLoading) {
            return false;
        }
        this.page++;
        this.fetchData();
    };



    render() {

        return (
            <YwxListView
                header={<WhiteSpace />}
                list={this.state.list}
                renderRow={item => (<WithdrawalLogItem key={item.id} info={item} />)}
                renderSeparator={(s, r) => <div key={`${s}-${r}`} style={{ height: 1, backgroundColor: '#eee' }} />}
                onRefresh={() => { this.onRefresh(0) }}
                onEndReached={() => { this.onEndReached(0) }}
                pageSize={this.state.pageSize}
                noMore={this.state.noMore}
            />
        );
    }
}